﻿using System;
using System.Collections.Generic;
using System.Web;

using System.Configuration;

/// <summary>
///CookieHelper 的摘要说明
/// </summary>
public class CookieManager
{
    public CookieManager()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }

    #region 管理员

    /// <summary>
    /// 是否登录
    /// </summary>
    public static bool IsLogined
    {
        get
        {
            return !String.IsNullOrEmpty(ID);
        }
    }

    /// <summary>
    /// 用户ID
    /// </summary>
    public static string ID
    {
        get
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];

            if (cookie == null || cookie["ID"] == null)
            {
                return String.Empty;
            }

            return cookie["ID"].ToString();
        }
        set
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];
            if (cookie == null)
            {
                cookie = new HttpCookie("User");
            }

            cookie.Values["ID"] = value.ToString();
            //cookie.Expires = DateTime.MaxValue;

            System.Web.HttpContext.Current.Response.SetCookie(cookie);
        }
    }

    /// <summary>
    /// 姓名
    /// </summary>
    public static string RealName
    {
        get
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];

            if (cookie == null || cookie["RealName"] == null)
            {
                return String.Empty;
            }

            return cookie["RealName"].ToString();
        }
        set
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];
            if (cookie == null)
            {
                cookie = new HttpCookie("User");
            }

            cookie.Values["RealName"] = value.ToString();

            System.Web.HttpContext.Current.Response.SetCookie(cookie);
        }
    }

    /// <summary>
    /// 角色ID
    /// </summary>
    public static string RoleID
    {
        get
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];

            if (cookie == null || cookie["RoleID"] == null)
            {
                return String.Empty;
            }

            return cookie["RoleID"].ToString();
        }
        set
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];
            if (cookie == null)
            {
                cookie = new HttpCookie("User");
            }

            cookie.Values["RoleID"] = value.ToString();

            System.Web.HttpContext.Current.Response.SetCookie(cookie);
        }
    }

    /// <summary>
    /// 角色权限
    /// </summary>
    public static string RolePermission
    {
        get
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];

            if (cookie == null || cookie["RolePermission"] == null)
            {
                return String.Empty;
            }

            return cookie["RolePermission"].ToString();
        }
        set
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];
            if (cookie == null)
            {
                cookie = new HttpCookie("User");
            }

            cookie.Values["RolePermission"] = value.ToString();

            System.Web.HttpContext.Current.Response.SetCookie(cookie);
        }
    }

    /// <summary>
    /// 角色菜单
    /// </summary>
    public static string RoleRights
    {
        get
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];

            if (cookie == null || cookie["RoleRights"] == null)
            {
                return String.Empty;
            }

            return cookie["RoleRights"].ToString();
        }
        set
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];
            if (cookie == null)
            {
                cookie = new HttpCookie("User");
            }

            cookie.Values["RoleRights"] = value.ToString();

            System.Web.HttpContext.Current.Response.SetCookie(cookie);
        }
    }

    /// <summary>
    /// 所属店铺ID SupperGuideId
    /// </summary>
    public static string CII
    {
        get
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];

            if (cookie == null || cookie["CII"] == null)
            {
                return String.Empty;
            }

            return cookie["CII"].ToString();
        }
        set
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];
            if (cookie == null)
            {
                cookie = new HttpCookie("User");
            }

            cookie.Values["CII"] = value.ToString();

            System.Web.HttpContext.Current.Response.SetCookie(cookie);
        }
    }

    /// <summary>
    /// 所属代理商ID PCII
    /// </summary>
    public static string PCII
    {
        get
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];

            if (cookie == null || cookie["PCII"] == null)
            {
                return String.Empty;
            }

            return cookie["PCII"].ToString();
        }
        set
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];
            if (cookie == null)
            {
                cookie = new HttpCookie("User");
            }

            cookie.Values["PCII"] = value.ToString();

            System.Web.HttpContext.Current.Response.SetCookie(cookie);
        }
    }

    /// <summary>
    /// 用户名
    /// </summary>
    public static string UserName
    {
        get
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];

            if (cookie == null || cookie["UserName"] == null)
            {
                return String.Empty;
            }

            return cookie["UserName"].ToString();
        }
        set
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];
            if (cookie == null)
            {
                cookie = new HttpCookie("User");
            }

            cookie.Values["UserName"] = value.ToString();

            System.Web.HttpContext.Current.Response.SetCookie(cookie);
        }
    }

    /// <summary>
    /// 所属店铺名称 SupperGuideName  SupperGuideDesc
    /// </summary>
    public static string CIIDES
    {
        get
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];

            if (cookie == null || cookie["CIIDES"] == null)
            {
                return String.Empty;
            }

            return cookie["CIIDES"].ToString();
        }
        set
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];
            if (cookie == null)
            {
                cookie = new HttpCookie("User");
            }

            cookie.Values["CIIDES"] = value.ToString();

            System.Web.HttpContext.Current.Response.SetCookie(cookie);
        }
    }

    /// <summary>
    /// 用户默认仓库ID
    /// </summary>
    public static string WHSWHS
    {
        get
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];

            if (cookie == null || cookie["WHSWHS"] == null)
            {
                return String.Empty;
            }

            return cookie["WHSWHS"].ToString();
        }
        set
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];
            if (cookie == null)
            {
                cookie = new HttpCookie("User");
            }

            cookie.Values["WHSWHS"] = value.ToString();

            System.Web.HttpContext.Current.Response.SetCookie(cookie);
        }
    }

    /// <summary>
    /// 用户默认仓库名称
    /// </summary>
    public static string WHSWHSName
    {
        get
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];

            if (cookie == null || cookie["WHSWHSName"] == null)
            {
                return String.Empty;
            }

            return cookie["WHSWHSName"].ToString();
        }
        set
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];
            if (cookie == null)
            {
                cookie = new HttpCookie("User");
            }

            cookie.Values["WHSWHSName"] = value.ToString();

            System.Web.HttpContext.Current.Response.SetCookie(cookie);
        }
    }
    /// <summary>
    /// 用户默认仓库名称
    /// </summary>
    public static string WHSLOC
    {
        get
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];

            if (cookie == null || cookie["WHSLOC"] == null)
            {
                return String.Empty;
            }

            return cookie["WHSLOC"].ToString();
        }
        set
        {
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];
            if (cookie == null)
            {
                cookie = new HttpCookie("User");
            }

            cookie.Values["WHSLOC"] = value.ToString();

            System.Web.HttpContext.Current.Response.SetCookie(cookie);
        }
    }


    /// <summary>
    /// 退出
    /// </summary>
    public static void Clear()
    {
        RemoveCookie("User");
    }

    #endregion

    #region 公共方法

    /// <summary>
    /// 删除 Cookie
    /// </summary>
    /// <param name="cookieName"></param>
    public static void RemoveCookie(string cookieName)
    {
        HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies[cookieName];

        if (cookie != null)
        {
            cookie.Expires = DateTime.Now.AddYears(-1);

            System.Web.HttpContext.Current.Response.SetCookie(cookie);
        }
    }

    #endregion
}
